<template>
	<el-dialog :title="'填写质检'" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="70px" label-position="right">
			<el-row>
				<el-col :span="8">
					<el-form-item label="往来单位">
						{{ pot.company_name }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="产品">
						{{ pot.material.spec }} {{ pot.material.name }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="颜色">
						{{ pot.color.code }} /{{ pot.color.name }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="缸号">
						{{ pot.dyelot }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="批号">
						{{ pot.lot_name }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="对样人">
						{{ pot.verifor.name }}
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="织片数" prop="textiles_count">
						<el-input v-model="form.textiles_count" />
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="合格？" prop="vertest_id">
						<el-switch v-model="form.vertest_id" :active-value="1" :inactive-value="0"></el-switch>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="织片机" prop="machine_id">
						<skDicSelect v-model="form.machine_id" :code="'Machine'" :placeholder="'请选择织片机'">
						</skDicSelect>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="包绞重" prop="j_qty">
						<el-input v-model="form.j_qty" />
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="包筒重" prop="t_qty">
						<el-input v-model="form.t_qty" />
					</el-form-item>
				</el-col>

				<el-col :span="12">
					<el-form-item label="质量问题" prop="qualityremark">
						<el-input v-model="form.qualityremark" type="textarea" maxlength="240" show-word-limit />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="处理方式" prop="treatment_method">
						<el-input v-model="form.treatment_method" type="textarea" maxlength="240" show-word-limit />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import tool from "@/utils/tool";
export default {
	emits: ["success", "closed"],
	components: { skDicSelect },
	data() {
		return {
			form: {},
			pot: { material: {}, verifor: {} },
			rules: {
				textiles_count: { required: true, message: "织片数必填" },
				machine_id: { required: true, message: "织片机器必选" },
			},
			visible: false,
			isSaveing: false,
		};
	},
	mounted() { },

	methods: {
		open() {
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.pro.pot.saveOqa.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit("success", this.form);
						this.visible = false;
						this.$message.success("开卡成功");
					}
				}
			});
		},
		//表单注入数据
		setData(data) {
			this.pot = Object.assign(this.pot, tool.removeNull(data));
			this.form = this.pot.oqa ?? { vertest_id: 1, pro_pot_id: this.pot.id };
			return this;
		},
	},
};
</script>